-- g_config 为全局变量,直接用
local ccutil = {}

local adapter = nil

ccutil.init = function ()
    if g_config.cc_dict_type == 'redis' then
        adapter = require "lib.cc_redis"
    elseif g_config.cc_dict_type == 'shared_dict' then
        adapter = require "lib.cc_shared_dict"
    else
        ngx.log(ngx.ERR,'cc_dict_type ['..g_config.cc_dict_type..'] ERROR. Just accepted "redis" or "shared_dict"')
        return
    end
    adapter.init()
end

ccutil.set = function(key, value, timeout)
    return adapter.set(key, value, timeout)
end

ccutil.incr = function(key)
    return adapter.incr(key)
end

ccutil.get = function(key)
    return adapter.get(key)
end

ccutil.set_ip = function(ip, timeout)
    return adapter.set_ip(ip, timeout)
end

ccutil.ip_exist = function(ip)
    return adapter.ip_exist(ip)
end

ccutil.clean_all_ccip = function()
    return adapter.clean_all_ccip()
end

return ccutil
